import { Component, Enum, ResolutionPolicy, UITransform, _decorator, v3, view } from "cc";
const {ccclass,property}=_decorator
enum PolicyEnum{
    UNKNOWN,
    FIXED_WIDTH,
    FIXED_HEIGHT,
}
@ccclass
export default class ImageScalePolicy extends Component{
    @property({type:Enum(PolicyEnum)})
    private policy=PolicyEnum.FIXED_WIDTH
    protected onLoad(): void {
        console.log('ImageScalePolicy.onLoad')
        const size=view.getDesignResolutionSize()
        console.log(size)
        const uit=this.getComponent(UITransform)
        let scale=1
        switch(this.policy){
            case PolicyEnum.FIXED_WIDTH:
                scale=size.width/uit.width
                console.log('适配宽度')
                break
            case PolicyEnum.FIXED_HEIGHT:
                scale=size.height/uit.height
                console.log('适配高度')
                break
        }
        this.node.setScale(v3(scale,scale,scale))
        console.log(scale)
    }
    
}